package com.css.fxfzypg.util;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Map;

public class PlatformObjectUtils {
    public static boolean isEmpty(Object obj){
        return obj == null;
    }


    public static boolean isEmpty(Object[] obj){
        return obj==null || obj.length==0;
    }
    /**
     * 判断字符串是否为空，null、""、"null"、" "返回true，其他返回false,
     * @param str
     * @return
     */
    public static boolean isEmpty(String str){
        return str == null || "".equals(str) || "null".equalsIgnoreCase(str) || "".equals(str.trim());
    }
    /**
     * 判断map是否为空，如果map为null或者empty返回true,其他返回false
     * @param map
     * @return
     */
    public static boolean isEmpty(Map map){
        return map == null || map.isEmpty();
    }
    /**
     * 判断collection是否为空，如果collection为null或者empty返回true,其他返回false
     * @param collection
     * @return
     */
    public static boolean isEmpty(Collection collection){
        return collection == null || collection.isEmpty();
    }

    public static boolean isNotEmpty(Object obj){
        return !isEmpty(obj) ;
    }


    public static boolean isNotEmpty(Object[] obj){
        return !isEmpty(obj) ;
    }
    public static boolean isNotEmpty(String str){
        return !isEmpty(str) ;
    }
    public static boolean isNotEmpty(Map map){
        return !isEmpty(map) ;
    }

    public static boolean isNotEmpty(Collection collection){
        return !isEmpty(collection) ;
    }

    public static boolean checkFieldAllNull(Object object) throws IllegalAccessException {
        for (Field f : object.getClass().getDeclaredFields()) {
            f.setAccessible(true);
            if (!isEmpty(f.get(object))) {
                return false;
            }
            f.setAccessible(false);
        }
        //父类public属性
        for (Field f : object.getClass().getFields()) {
            f.setAccessible(true);
            if (!isEmpty(f.get(object))) {
                return false;
            }
            f.setAccessible(false);
        }
        return true;
    }

}
